package com.springcloud.sc.ucpv5.client.commondata.data;

import java.io.Serializable;

import com.springcloud.sc.ucpv5.client.commondata.datachange.DataExChange;
import com.google.protobuf.Message;
import lombok.Data;

/**
 * Generated from IDL struct "User".
 *
 * @author JacORB IDL compiler V 2.3-beta-2, 14-Oct-2006
 * @version generated at 2014-10-29 11:48:54
 */

@Data
public final class User extends DataExChange implements Serializable {
    public User() {
    }

    public String UserTelno = "";
    public String UserName = "";
    public String password = "";
    public int UserType;
    public String addtime = "";
    public int Priority;
    public int UserStatus;
    public String GrpList = "";
    public String longitude = "";
    public String latitude = "";
    public String zoom = "";
    public String Desc = "";
    public String UserIconName = "";
    public int UserShowType;
    public int UserMediaType;
    public String UserMediaID = "";

    public User(String UserTelno, String UserName, String password, int UserType, String addtime, int Priority,
                int UserStatus, String GrpList, String longitude, String latitude, String zoom, String Desc,
                String UserIconName, int UserShowType, int UserMediaType, String UserMediaID) {
	this.UserTelno = UserTelno;
	this.UserName = UserName;
	this.password = password;
	this.UserType = UserType;
	this.addtime = addtime;
	this.Priority = Priority;
	this.UserStatus = UserStatus;
	this.GrpList = GrpList;
	this.longitude = longitude;
	this.latitude = latitude;
	this.zoom = zoom;
	this.Desc = Desc;
	this.UserIconName = UserIconName;
	this.UserShowType = UserShowType;
	this.UserMediaType = UserMediaType;
	this.UserMediaID = UserMediaID;
    }

    public Message dataChangeCommonToProBufData() {
	try {
	    com.proto.uuos_sdk_pb.User.Builder builder_dst = com.proto.uuos_sdk_pb.User.newBuilder();
	    builder_dst.setUserTelno(UserTelno);
	    builder_dst.setUserName(UserName);
	    builder_dst.setPassword(password);
	    builder_dst.setUserType(UserType);
	    builder_dst.setPriority(Priority);
	    builder_dst.setUserStatus(UserStatus);
	    builder_dst.setDesc(Desc);
	    builder_dst.setAddtime(addtime);
	    builder_dst.setLongitude(longitude);
	    builder_dst.setLatitude(latitude);
	    builder_dst.setZoom(zoom);
	    builder_dst.setUserIconName(UserIconName);
	    builder_dst.setUserShowType(UserShowType);
	    builder_dst.setUserMediaType(UserMediaType);
	    builder_dst.setUserMediaID(UserMediaID);

	    String[] GrpList_ = GrpList.split("#");
	    for (String tmp : GrpList_) {
		if (tmp != null && !tmp.equals("")) {
		    builder_dst.addGrpList(tmp);
		}
	    }

	    Message pbMessage = builder_dst.build();
	    return pbMessage;
	} catch (Exception e) {
	    // TODO: handle exception
	}

	return null;
    }

    /**
     * 从probuf对象获取当前对象
     * 
     * @param builder_src
     * @return
     */
    public void dataChangeProBufDataToCommon(Message builder_src) {
	try {
	    com.proto.uuos_sdk_pb.User userInfo = (com.proto.uuos_sdk_pb.User) builder_src;

	    UserTelno = userInfo.getUserTelno();
	    UserName = userInfo.getUserName();
	    password = userInfo.getPassword();
	    UserType = userInfo.getUserType();
	    Priority = userInfo.getPriority();
	    UserStatus = userInfo.getUserStatus();
	    Desc = userInfo.getDesc();
	    addtime = userInfo.getAddtime();
	    longitude = userInfo.getLongitude();
	    latitude = userInfo.getLatitude();
	    zoom = userInfo.getZoom();
	    UserIconName = userInfo.getUserIconName();
	    UserShowType = userInfo.getUserShowType();
	    UserMediaType = userInfo.getUserMediaType();
	    UserMediaID = userInfo.getUserMediaID();

	    //
	    StringBuilder builder = new StringBuilder();
	    for (int i = 0; i < userInfo.getGrpListCount(); i++) {
		builder.append(userInfo.getGrpList(i));
		if (i < (userInfo.getGrpListCount() - 1)) {
		    builder.append("#");
		}

	    }
	    GrpList = builder.toString();

	} catch (Exception e) {
	    e.printStackTrace();
	}
    }
}
